import React from 'react'
import { getMusicURLApi } from "../api/jxx"

class Audio extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      autoplay: true,
      currentTime: 0
    }
    // 获取audio真实DOM
    this.audio = React.createRef()
  }



  componentDidUpdate() {
    // 更改播放状态
    if (!this.props.audio) {
      this.audio.current.pause()
    } else {
      this.audio.current.play()
    }
  }
  //每秒运行4次
  getTime(time) {
    this.props.getTimenow(1)
  }

  render() {

    return (
      <audio
        src={this.props.musicurl}
        ref={this.audio}
        autoPlay={this.props.audio}
        onTimeUpdate={this.getTime.bind(this)}
      ></audio>
    )
  }
}
export default Audio;